package com.iwhalecloud.citybrain.flow.platform.manager.application.common.threadlocal;

import com.iwhalecloud.citybrain.flow.platform.manager.domain.model.log.CommonOperateLogContentVo;
import com.iwhalecloud.citybrain.flow.platform.manager.domain.model.log.FlowCommonOperateLogVo;

/**
 * @author lilh
 * @date 2019-08-19 16:24
 */
public abstract class CommonOperateLogHolder {

    private static ThreadLocal<FlowCommonOperateLogVo> holder = ThreadLocal.withInitial(FlowCommonOperateLogVo::new);

    private static ThreadLocal<CommonOperateLogContentVo> contentHolder = ThreadLocal.withInitial(CommonOperateLogContentVo::new);

    private static ThreadLocal<String> participantNameHolder = new ThreadLocal<>();

    private static ThreadLocal<Boolean> processInstanceCompletedHolder = ThreadLocal.withInitial(() -> false);

    private static ThreadLocal<Boolean> fromSdk = ThreadLocal.withInitial(() -> false);

    public static void setCommonOperateLog(FlowCommonOperateLogVo entity) {
        holder.set(entity);
    }

    public static FlowCommonOperateLogVo getCommonOperateLog() {
        return holder.get();
    }

    public static void remove() {
        holder.remove();
    }


    public static void setContent(CommonOperateLogContentVo content) {
        contentHolder.set(content);
    }

    public static CommonOperateLogContentVo getContent() {
        return contentHolder.get();
    }

    public static void removeContent() {
        contentHolder.remove();
    }

    public static void setParticipantName(String participantName) {
        participantNameHolder.set(participantName);
    }

    public static String getParticipantName() {
        return participantNameHolder.get();
    }

    public static void removeParticipant() {
        participantNameHolder.remove();
    }

    public static void setProcessInstanceCompletedFlag(Boolean flag) {
        processInstanceCompletedHolder.set(flag);
    }

    public static Boolean getProcessInstanceCompletedFlag() {
        return processInstanceCompletedHolder.get();
    }

    public static Boolean getFromSdk() {
        return fromSdk.get();
    }

    public static void setFromSdk(Boolean isFromSdk) {
        fromSdk.set(isFromSdk);
    }

    public static void removeAll() {
        remove();
        removeContent();
        removeParticipant();
        processInstanceCompletedHolder.remove();
        fromSdk.remove();
    }
}
